package utils;

import news.News;
import news.NewsEvent;
import reader.Reader;
import writer.Journalist;

public class Main {
		
		public static void main(String[] args) {
			
			//System.out.println();
			
			try {
				
				/**
				 * PUBLISHERS
				 */
				
				Journalist remus = new Journalist("Remus") ;
				remus.addTopic("EconomyTopic");
				
				Journalist cipri = new Journalist("Cipri") ;
				cipri.addTopic("SportTopic");
				
				Journalist viktor = new Journalist("Viktor") ;
				viktor.addTopic("EconomyTopic");
				
				Journalist laura = new Journalist("Laura") ;
				laura.addTopic("LifeStyleTopic");
				
				Journalist manu = new Journalist("Manu") ;
				manu.addTopic("SportTopic");
				manu.addTopic("EconomyTopic");
				
				/**
				 * SUBSCRIBERS
				 */				
				
				Reader reader1 = new Reader("reader1", "psw");
				//filter: author
				reader1.addTopic("EconomyTopic","author = 'Remus' OR author = 'Viktor'");
				//filter: author && subdomain
				reader1.addTopic("SportTopic","subdomain = 'PingPong' and author = 'Cipri'");
				new Thread(reader1).start();
				
				
				Reader reader2= new Reader("reader2", "psw");
				//filter: -
				reader2.addTopic("EconomyTopic","");
				//filter: author && subdomain
				reader2.addTopic("SportTopic","");
				new Thread(reader2).start();
				
				Reader reader3= new Reader("reader3", "psw");
				new Thread(reader3).start();
				
				Reader reader4= new Reader("reader4", "psw");
				new Thread(reader4).start();
				
				/**
				 * PUBLISH NEWS 
				 */
				
				
				laura.publishNews("LifeStyleTopic", new News("Euro se prabuseste", "Laura", System.currentTimeMillis(), System.currentTimeMillis(),"", "new house style"), NewsEvent.NEWS_PUBLISHED);
				
				// 1 reader1
				remus.publishNews("EconomyTopic", new News("Euro se prabuseste", "Remus", System.currentTimeMillis(), System.currentTimeMillis(),"", "remus euro content"), NewsEvent.NEWS_PUBLISHED) ;
							
				// 0 reader1
				cipri.publishNews("SportTopic", new News("Dolarul se prabuseste", "Cipri", System.currentTimeMillis(), System.currentTimeMillis(), "", "cipri content"), NewsEvent.NEWS_PUBLISHED);
				
				// 1 reader1 
				remus.publishNews("EconomyTopic", new News("Leul se prabuseste", "Remus", System.currentTimeMillis(), System.currentTimeMillis(), "", "remus leu content"), NewsEvent.NEWS_PUBLISHED);
				
				// 1 reader1 
				cipri.publishNews("SportTopic", new News("Dacia castiga", "Cipri", System.currentTimeMillis(), System.currentTimeMillis(), "PingPong", "cipri sport content"), NewsEvent.NEWS_PUBLISHED);
				
				//1 reader1
				viktor.publishNews("EconomyTopic", new News("Lira Sterlina Creste", "Viktor", System.currentTimeMillis(), System.currentTimeMillis(), "", "viktor leu content"), NewsEvent.NEWS_PUBLISHED);
				
				
				Thread.sleep(3000); 				
				
				reader1.unSubscribe("EconomyTopic");
				
				
				// 0 reader1
				remus.publishNews("EconomyTopic", new News("Euro se prabuseste", "Remus", System.currentTimeMillis(), System.currentTimeMillis(),"", "remus euro content2"), NewsEvent.NEWS_MODIFIED) ;
				
				
				
				// 0 - nu am voie sa public 
				cipri.publishNews("EconomyTopic", new News("Dolarul se prabuseste", "Cipri", System.currentTimeMillis(), System.currentTimeMillis(), "", "cipri content2"), NewsEvent.NEWS_MODIFIED);
				
				// 1 reader1
				cipri.publishNews("SportTopic", new News("Renault sport", "Cipri", System.currentTimeMillis(), System.currentTimeMillis(), "PingPong", "cipri sport content") , NewsEvent.NEWS_PUBLISHED);
				
				// 1 reader1
				cipri.publishNews("SportTopic", new News("Renault sport", "Cipri", System.currentTimeMillis(), System.currentTimeMillis(), "PingPong", "cipri sport content modified") , NewsEvent.NEWS_MODIFIED);
				
				remus.publishNews("EconomyTopic", new News("Euro2 se prabuseste", "Remus", System.currentTimeMillis(), System.currentTimeMillis(),"", "remus euro content2"), NewsEvent.NEWS_PUBLISHED) ;
				
				//1 reader1
				cipri.publishNews("SportTopic", new News("Renault sport", "Cipri", System.currentTimeMillis(), System.currentTimeMillis(), "PingPong", "cipri sport content"), NewsEvent.NEWS_DELETED);
				
				
				
				/**
				 * 
				 */
				
				reader2.addTopic("LifeStyleTopic", "");
				reader3.addTopic("LifeStyleTopic", "");
				reader4.addTopic("LifeStyleTopic", "");
				
				laura.publishNews("LifeStyleTopic", new News("New house style", "Laura", System.currentTimeMillis(), System.currentTimeMillis(),"", "new house style"), NewsEvent.NEWS_PUBLISHED);
				
				
				Thread.sleep(10000); 	
				
				
				
				System.exit(0);
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
		}
	
}
